package com.github_dididipapa.mall.product.app;

import java.util.Arrays;
import java.util.List;
//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github_dididipapa.mall.product.dto.BrandRelationDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.github_dididipapa.mall.product.entity.CategoryBrandRelationEntity;
import com.github_dididipapa.mall.product.service.CategoryBrandRelationService;
import com.github_dididipapa.common.utils.R;



/**
 * 品牌分类关联
 *
 * @author dididipapa
 * @email not_found@404.com
 * @date 2025-04-26 18:51:12
 */
@Slf4j
@Validated
@RestController
@RequestMapping("product/categorybrandrelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 获取当前品牌关联的所有分类的列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("product:categorybrandrelation:list")
    public R list(@RequestParam("brandId") Long brandId){
        List<CategoryBrandRelationEntity> brandList = categoryBrandRelationService.list(new QueryWrapper<CategoryBrandRelationEntity>()
                .eq("brand_id", brandId)
        );

        return R.ok().put("data", brandList);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:categorybrandrelation:info")
    public R info(@PathVariable("id") Long id){
		CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);

        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:categorybrandrelation:save")
    public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
        categoryBrandRelationService.saveDetail(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:categorybrandrelation:update")
    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.updateById(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:categorybrandrelation:delete")
    public R delete(@RequestBody Long[] ids){
		categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * @description:
     * @author: dididi_papa
     * @date: 2025/6/15 下午4:17
     * @param: [brandId]
     * @return: com.github_dididipapa.common.utils.R
     **/
    @GetMapping("/catelog/list")
    public R catelogList(@RequestParam("brandId") Long brandId){
        List<CategoryBrandRelationEntity> data = categoryBrandRelationService.getCategoryByBrandId(brandId);
        return R.ok().put("data", data);
    }

    /**
     * @description:
     * @author: dididi_papa
     * @date: 2025/6/15 下午4:17
     * @param: [catId]
     * @return: com.github_dididipapa.common.utils.R
     **/
    @GetMapping("/brands/list")
    public R getRelationList(@RequestParam("catId") Long catId){
        List<BrandRelationDto> data = categoryBrandRelationService.getBrandByCatId(catId);
        return R.ok().put("data", data);
    }
}
